---
order: 4
title: Ambient Light
type: Graphics
group: Light
label: Graphics/Light
---

In addition to real-time computed direct light sources, we generally need to pre-bake lighting offline as ambient light for real-time sampling. This method effectively captures the global illumination and atmosphere of the environment, making objects blend better into their surroundings.

<Image src="https://gw.alipayobjects.com/zos/OasisHub/23397353-5434-4bde-ace7-72c8731d5581/image-20231227151844040.png" />

## Editor Usage

### 1. Ambient Diffuse

<Image src="https://gw.alipayobjects.com/zos/OasisHub/a0bec326-364b-42ca-9172-0319b47e0256/image-20240219163916257.png" alt="image-20240219163916257" style={{ zoom: "50%" }} />

| Property | Function |
| :-- | :-- |
| Source | Specifies whether the diffuse source is `Background` or `Solid Color`, with the default source being `Background`. `Background` means using the baked spherical harmonics parameters as the diffuse color; `Solid Color` means using a solid color as the diffuse color. |
| Intensity | Diffuse intensity |

### 2. Ambient Specular

<Image src="https://gw.alipayobjects.com/zos/OasisHub/bec5c785-1969-4f3d-8d04-eff02595cbca/image-20240219163941010.png" alt="image-20240219163941010" style={{ zoom: "50%" }} />

| Property | Function |
| :-- | :-- |
| Source | Specifies whether the specular source is `Background` or `Custom`, with the default source being `Background`. `Background` means using the pre-filtered environment map baked from the background as the specular reflection; `Custom` means you can separately bake an HDR map as the environment reflection. |
| Intensity | Specular intensity |

## Script Usage

After obtaining the URL of the baked product through the [baking tutorial](/en/docs/graphics/light/bake/), load and parse it through the engine's EnvLoader:

```typescript
engine.resourceManager
  .load<AmbientLight>({
    type: AssetType.Env,
    url: "https://gw.alipayobjects.com/os/bmw-prod/89c54544-1184-45a1-b0f5-c0b17e5c3e68.bin"
  })
  .then((ambientLight) => {
    scene.ambientLight = ambientLight;

    // 可以调节漫反射、镜面反射强度，默认为1
    // ambientLight.diffuseIntensity = 1;
    // ambientLight.specularIntensity = 1;

    // 预滤波环境贴图（ambientLight.specularTexture）还可以作为场景的背景
    // skyMaterial.texture = ambientLight.specularTexture;
    // 由于烘焙产物的颜色编码方式是 RGBM，因此作为背景时需要将解码设置为 textureDecodeRGBM
    // skyMaterial.textureDecodeRGBM = true;
  });
```
